<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('岗位列表')" />
</head>
<body class="gray-bg">
    <!--页面的主体-->
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="serviceItem-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                名称：<input type="text" name="name"/>
                            </li>
                            <li>
                                是否套餐：
                                <select name="carPackage" th:with="type=${@dict.getType('si_car_package')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
                                </select>
                            </li>
                            <li>
                                服务分类：
                                <select name="serviceCatalog" th:with="type=${@dict.getType('si_service_catalog')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
                                </select>
                            </li>
                            <li>
                                审核状态：
                                <select name="auditStatus" th:with="type=${@dict.getType('si_audit_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
                                </select>
                            </li>
                            <li>
                                销售状态：
                                <select name="saleStatus" th:with="type=${@dict.getType('si_sale_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a id="auditBtn" class="btn btn-warning disabled">
                    <i class="fa fa-plus"></i> 发起审核
                </a>
                <a id="testBtn" class="btn btn-warning">
                    <i class="fa fa-plus"></i> 测试审核
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <!--页脚的代码片段-->
    <th:block th:include="common/include :: footer" />
    <!--数据渲染脚本-->
    <script th:inline="javascript">
        var prefix = ctx + "/business/serviceItem";
        var carPackageDatas = [[${@dict.getType('si_car_package')}]];
        var serviceCatalogDatas = [[${@dict.getType('si_service_catalog')}]];
        var auditStatusDatas = [[${@dict.getType('si_audit_status')}]];
        var saleStatusDatas = [[${@dict.getType('si_sale_status')}]];
        $(function(){
            var options = {
                url: prefix + "/query",					//查询数据的请求地址
                createUrl: prefix + "/addPage",			//点击新增跳转的页面地址
                updateUrl: prefix + "/editPage?id={id}",//点击编辑跳转的页面地址
                removeUrl: prefix + "/remove",
                modalName: "服务单项",
                columns:[
                    {
                        checkbox:true
                    },
                    {
                        field:'name',
                        title:'服务名称'
                    },
                    {
                        field:'originalPrice',
                        title:'单项原价'
                    },
                    {
                        field:'discountPrice',
                        title:'单项折扣价'
                    },
                    {
                        field:'carPackage',
                        title:'是否套餐',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(carPackageDatas, value);
                        }
                    },
                    {
                        field:'info',
                        title:'备注信息',
                        formatter: function(value, row, index) {
                            return $.table.tooltip(value,5);
                        }
                    },
                    {
                        field:'serviceCatalog',
                        title:'服务分类',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(serviceCatalogDatas, value);
                        }
                    },
                    {
                        field:'auditStatus',
                        title:'审核状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(auditStatusDatas, value);
                        }
                    },
                    {
                        field:'saleStatus',
                        title:'销售状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(saleStatusDatas, value);
                        }
                    },
                    {
                        title:'操作',
                        formatter: function(value, row, index) {
                            var actions = [];
                            //1.上架状态不能修改
                            //2.如果处于审核中
                            var editFlag = "";
                            if(row.saleStatus==1 || row.auditStatus == 1){
                                editFlag = "disabled";
                            }
                            actions.push('<a class="btn btn-success btn-xs '+editFlag+'" href="javascript:void(0)" ' +
                                'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            if(row.saleStatus==0){
                                var saleOnFlag = "";
                                //是套餐  &&  状态不是审核通过
                                if(row.carPackage==1 && row.auditStatus!=2){
                                    saleOnFlag = "disabled";
                                }
                                //处于下架状态
                                actions.push('<a class="btn btn-info btn-xs '+saleOnFlag+'" href="javascript:void(0)" ' +
                                    'onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>上架</a> ');
                            }else{
                                //处于上架状态
                                actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" ' +
                                    'onclick="saleOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>下架</a> ');
                            }
                            return actions.join("");
                        }
                    }
                ]
            };
            $.table.init(options)
        })
        function saleOn(id){
            $.modal.confirm("是否要将该服务单项进行上架操作?",function(){
                $.operate.get(prefix+"/saleOn?id="+id);
            });
        }
        function saleOff(id){
            $.modal.confirm("是否要将该服务单项进行下架操作?",function(){
                $.operate.get(prefix+"/saleOff?id="+id);
            });
        }
        $("#bootstrap-table").on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table", function () {
            var rows = $('#bootstrap-table').bootstrapTable('getSelections');
            if(rows.length==1){
                //单选
                var row = rows[0];
                if(row.carPackage){
                    //是套餐
                    if(row.auditStatus==0 || row.auditStatus==3){
                        $("#auditBtn").removeClass("disabled");
                        return;
                    }
                }
            }
            $("#auditBtn").addClass("disabled");
        });
        $("#auditBtn").click(function(){
            $.modal.confirm("是否需要发起套餐审核流程?",function(){
                var row = $('#bootstrap-table').bootstrapTable('getSelections')[0];
                $.modal.open("发起审核","/business/serviceItem/auditPage?id="+row.id);
            });
        });
    </script>
    <script>
        $("#testBtn").on("click",function(){
            alert(8888);
        });
    </script>
</body>
</html>